package com.axter.libs.photo.choosephoto;

import android.view.View;
import android.widget.TextView;

import com.axter.libs.photo.R;
import com.axter.libs.photo.bean.MediaInfo;

import java.util.Locale;

/**
 * Created by zhaobo on 2016/10/14.
 */

public class ChoosePhotoViewHolderVideo extends ChoosePhotoViewHolderImage {
    TextView tv_time;

    public ChoosePhotoViewHolderVideo(ChoosePhotoAdapter adapter) {
        super(adapter);
    }

    @Override
    public Object getContentView() {
        return R.layout.choosephoto_item_video;
    }

    @Override
    public void bindViews(View view) {
        super.bindViews(view);
        tv_time = (TextView) view.findViewById(R.id.tv_time);
    }

    @Override
    public void handleData(MediaInfo mediaInfo, int i) {
        super.handleData(mediaInfo, i);
        tv_time.setText(toTimer(mediaInfo.getDuration()));
    }

    /**
     * 00:00
     *
     * @param millisecond 毫秒
     * @return
     */
    public static String toTimer(long millisecond) {
        long second = millisecond / 1000; // 秒
        long minute = second / 60;// 分
        long lastSecond = second % 60;// 余秒

        return String.format(Locale.CANADA, "%02d:%02d", minute, lastSecond);
    }
}
